package com.vvv.shortlink.admin.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vvv.shortlink.common.convention.result.Result;
import com.vvv.shortlink.admin.remote.ShortLinkProjectClient;
import com.vvv.shortlink.admin.remote.dto.req.LinkStatsAccessRecordReqDTO;
import com.vvv.shortlink.admin.remote.dto.req.LinkStatsReqDTO;
import com.vvv.shortlink.admin.remote.dto.resp.LinkStatsAccessRecordRespDTO;
import com.vvv.shortlink.admin.remote.dto.resp.LinkStatsRespDTO;
import com.vvv.shortlink.common.toolkit.UserContext;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author vvv
 * @date 2024/2/21 17 38
 * discription
 */
@RestController
@RequiredArgsConstructor
public class AdminLinkStatsController {

    private final ShortLinkProjectClient shortLinkProjectClient;


    /**
     * 访问单个短链接指定时间内监控数据
     */
    @GetMapping("/api/short-link/admin/v1/stats")
    public Result<LinkStatsRespDTO> shortLinkStats(LinkStatsReqDTO requestParam) {
        requestParam.setUserId(UserContext.getUserId());
        return shortLinkProjectClient.shortLinkStats(requestParam);
    }

    /**
     * 分页查询单个短链接监控访问记录
     */
    @GetMapping("/api/short-link/admin/v1/stats/access-record")
    public Result<Page<LinkStatsAccessRecordRespDTO>> shortLinkStatsAccessRecord(LinkStatsAccessRecordReqDTO requestParam) {
        requestParam.setUserId(UserContext.getUserId());
        return shortLinkProjectClient.shortLinkStatsAccessRecord(requestParam);
    }
}
